import Vue from 'vue'
import moment from 'moment'
import 'moment/locale/zh-cn'
moment.locale('zh-cn')

Vue.filter('NumberFormat', function (value) {
  if (!value) {
    return '0'
  }
  const intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断
  return intPartFormat
})

Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})

Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})

// 劳务状态
const statusMap = {
  0: {
      status: 'default',
      text: '已停用'
  },
  1: {
      status: 'processing',
      text: '运行中'
  },
  2: {
      status: 'success',
      text: '已上线'
  },
  3: {
      status: 'error',
      text: '异常'
  }
}
Vue.filter('statusFilter', function (type) {
  return statusMap[type].text;
})

Vue.filter('statusTypeFilter', function (type) {
  return statusMap[type].status
})

// 项目状态
const projectStatusMap = {
  0: {
      status: 'default',
      text: '已停用'
  },
  1: {
      status: 'processing',
      text: '进行中'
  },
  2: {
      status: 'default',
      text: '已结束'
  },
  3: {
      status: 'error',
      text: '异常'
  }
}
Vue.filter('projectStatusFilter', function (type) {
  return projectStatusMap[type].text;
})

Vue.filter('projectStatusTypeFilter', function (type) {
  return projectStatusMap[type].status
})

// 合同状态
const contractStatusMap = {
  0: {
      status: 'default',
      text: '已停用'
  },
  1: {
      status: 'processing',
      text: '使用中'
  },
}
Vue.filter('contractStatusFilter', function (type) {
  return contractStatusMap[type].text;
})

Vue.filter('contractStatusTypeFilter', function (type) {
  return contractStatusMap[type].status
})

// 账户类型
Vue.filter('accountTypeFilter', function (type) {
  var typeStr = '一般账户'
  switch(type){
    case 2:
      typeStr = '基本账户';
      break;
    case 3:
      typeStr = '临时账户';
      break;
    case 4:
      typeStr = '专用账户';
      break;
  }
  return typeStr;
})

// 联动设置
Vue.filter('linkageTypeFilter', function (type) {
  var typeStr = '未开通'
  switch(type){
    case 1:
      typeStr = '发起方';
      break;
    case 2:
      typeStr = '授权方';
      break;
  }
  return typeStr;
})

// 结算单状态
Vue.filter('settlementStateFilter', function (state) {
  var typeStr = '待审核'
  switch(state){
    case 1:
      typeStr = '待支付';
      break;
    case 2:
      typeStr = '待授权';
      break;
    case 3:
      typeStr = '已支付';
      break;
    case 4:
      typeStr = '部分支付失败';
      break;
    case 5:
      typeStr = '已驳回';
      break;
    case 6:
      typeStr = '已取消';
      break;
    case 7:
      typeStr = '支付失败';
      break;
    case 8:
      typeStr = '支付中';
      break;
    case 9:
      typeStr = '已结束';
      break;
  }
  return typeStr;
})

// 发票状态
Vue.filter('invoiceStateFilter', function (state) {
  var typeStr = '待审核'
  switch(state){
    case 2:
      typeStr = '待开票';
      break;
    case 3:
      typeStr = '待邮寄';
      break;
    case 4:
      typeStr = '已邮寄';
      break;
    case 8:
      typeStr = '已拒绝';
      break;
    case 9:
      typeStr = '已结束';
      break;
  }
  return typeStr;
})

// 企业认证状态
Vue.filter('realNameStatusFilter', function (state) {
  var typeStr = '未实名'
  switch(state){
    case 1:
      typeStr = '实名中';
      break;
    case 2:
      typeStr = '实名失败';
      break;
    case 3:
      typeStr = '已实名';
      break;
  }
  return typeStr;
})